from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-18 14:02:34.146413
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 18, Apr, 2022
Time: 14:02:42
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0063
Nobs: 630.000 HQIC: -49.3947
Log likelihood: 7681.66 FPE: 2.76073e-22
AIC: -49.6414 Det(Omega_mle): 2.39591e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.331213 0.062992 5.258 0.000
L1.Burgenland 0.105877 0.039702 2.667 0.008
L1.Kärnten -0.110631 0.020803 -5.318 0.000
L1.Niederösterreich 0.194865 0.082989 2.348 0.019
L1.Oberösterreich 0.119942 0.081816 1.466 0.143
L1.Salzburg 0.259558 0.042120 6.162 0.000
L1.Steiermark 0.044440 0.055448 0.801 0.423
L1.Tirol 0.104820 0.044882 2.335 0.020
L1.Vorarlberg -0.065252 0.039593 -1.648 0.099
L1.Wien 0.021463 0.072615 0.296 0.768
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.045211 0.134863 0.335 0.737
L1.Burgenland -0.036447 0.085001 -0.429 0.668
L1.Kärnten 0.041636 0.044538 0.935 0.350
L1.Niederösterreich -0.199761 0.177675 -1.124 0.261
L1.Oberösterreich 0.454651 0.175163 2.596 0.009
L1.Salzburg 0.283656 0.090177 3.146 0.002
L1.Steiermark 0.110262 0.118711 0.929 0.353
L1.Tirol 0.307281 0.096090 3.198 0.001
L1.Vorarlberg 0.026815 0.084766 0.316 0.752
L1.Wien -0.024853 0.155464 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191164 0.032197 5.937 0.000
L1.Burgenland 0.088930 0.020293 4.382 0.000
L1.Kärnten -0.007461 0.010633 -0.702 0.483
L1.Niederösterreich 0.244666 0.042418 5.768 0.000
L1.Oberösterreich 0.159976 0.041819 3.825 0.000
L1.Salzburg 0.040306 0.021529 1.872 0.061
L1.Steiermark 0.027169 0.028341 0.959 0.338
L1.Tirol 0.083507 0.022941 3.640 0.000
L1.Vorarlberg 0.054639 0.020237 2.700 0.007
L1.Wien 0.118807 0.037116 3.201 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109541 0.032237 3.398 0.001
L1.Burgenland 0.042921 0.020318 2.112 0.035
L1.Kärnten -0.013291 0.010646 -1.248 0.212
L1.Niederösterreich 0.173899 0.042471 4.095 0.000
L1.Oberösterreich 0.333691 0.041871 7.970 0.000
L1.Salzburg 0.101140 0.021556 4.692 0.000
L1.Steiermark 0.112835 0.028376 3.976 0.000
L1.Tirol 0.091431 0.022969 3.981 0.000
L1.Vorarlberg 0.061008 0.020262 3.011 0.003
L1.Wien -0.013848 0.037162 -0.373 0.709
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109844 0.060381 1.819 0.069
L1.Burgenland -0.045515 0.038057 -1.196 0.232
L1.Kärnten -0.045782 0.019941 -2.296 0.022
L1.Niederösterreich 0.137997 0.079548 1.735 0.083
L1.Oberösterreich 0.163736 0.078424 2.088 0.037
L1.Salzburg 0.283717 0.040374 7.027 0.000
L1.Steiermark 0.059690 0.053149 1.123 0.261
L1.Tirol 0.160509 0.043021 3.731 0.000
L1.Vorarlberg 0.098487 0.037951 2.595 0.009
L1.Wien 0.079550 0.069604 1.143 0.253
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055798 0.047280 1.180 0.238
L1.Burgenland 0.026770 0.029800 0.898 0.369
L1.Kärnten 0.052933 0.015614 3.390 0.001
L1.Niederösterreich 0.197203 0.062289 3.166 0.002
L1.Oberösterreich 0.331130 0.061409 5.392 0.000
L1.Salzburg 0.037100 0.031614 1.174 0.241
L1.Steiermark 0.011040 0.041618 0.265 0.791
L1.Tirol 0.121814 0.033687 3.616 0.000
L1.Vorarlberg 0.066728 0.029717 2.245 0.025
L1.Wien 0.100455 0.054502 1.843 0.065
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168479 0.056805 2.966 0.003
L1.Burgenland 0.005407 0.035803 0.151 0.880
L1.Kärnten -0.065759 0.018760 -3.505 0.000
L1.Niederösterreich -0.102302 0.074838 -1.367 0.172
L1.Oberösterreich 0.206647 0.073780 2.801 0.005
L1.Salzburg 0.055210 0.037983 1.454 0.146
L1.Steiermark 0.245576 0.050002 4.911 0.000
L1.Tirol 0.501327 0.040474 12.386 0.000
L1.Vorarlberg 0.063748 0.035704 1.785 0.074
L1.Wien -0.075852 0.065482 -1.158 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146998 0.063000 2.333 0.020
L1.Burgenland -0.001236 0.039707 -0.031 0.975
L1.Kärnten 0.062519 0.020806 3.005 0.003
L1.Niederösterreich 0.169525 0.082999 2.042 0.041
L1.Oberösterreich -0.053272 0.081826 -0.651 0.515
L1.Salzburg 0.207558 0.042125 4.927 0.000
L1.Steiermark 0.139878 0.055455 2.522 0.012
L1.Tirol 0.058060 0.044888 1.293 0.196
L1.Vorarlberg 0.148625 0.039598 3.753 0.000
L1.Wien 0.123700 0.072624 1.703 0.089
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377750 0.037165 10.164 0.000
L1.Burgenland -0.003061 0.023424 -0.131 0.896
L1.Kärnten -0.020670 0.012274 -1.684 0.092
L1.Niederösterreich 0.206240 0.048963 4.212 0.000
L1.Oberösterreich 0.230512 0.048270 4.775 0.000
L1.Salzburg 0.038110 0.024850 1.534 0.125
L1.Steiermark -0.013076 0.032714 -0.400 0.689
L1.Tirol 0.089146 0.026480 3.367 0.001
L1.Vorarlberg 0.053592 0.023359 2.294 0.022
L1.Wien 0.043810 0.042842 1.023 0.306
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036688 0.110791 0.173170 0.139839 0.101327 0.081723 0.037233 0.210818
Kärnten 0.036688 1.000000 -0.024596 0.131913 0.050842 0.086796 0.443740 -0.065703 0.090034
Niederösterreich 0.110791 -0.024596 1.000000 0.316508 0.124802 0.276744 0.069968 0.155182 0.292773
Oberösterreich 0.173170 0.131913 0.316508 1.000000 0.216914 0.299283 0.167860 0.139486 0.241266
Salzburg 0.139839 0.050842 0.124802 0.216914 1.000000 0.125997 0.093733 0.107380 0.126980
Steiermark 0.101327 0.086796 0.276744 0.299283 0.125997 1.000000 0.135976 0.110441 0.039238
Tirol 0.081723 0.443740 0.069968 0.167860 0.093733 0.135976 1.000000 0.065908 0.152036
Vorarlberg 0.037233 -0.065703 0.155182 0.139486 0.107380 0.110441 0.065908 1.000000 -0.002992
Wien 0.210818 0.090034 0.292773 0.241266 0.126980 0.039238 0.152036 -0.002992 1.000000